﻿/*
创建人：zhangrj
日期：2022-10-29
描述：检验实测值录入页面js
*/
var page = {
    rootPath: getRootPath(), //网站根路径
    pageTotal: 0,
    pageSize: 10,
    pageNumber: 1,
    uname: "", //用户编号
    url: getRootPath() + "/Ashx/InputCheckItemNewFormHandler.ashx", //后台处理url,
    init: function () {
        page.initPageData();
        customizedEasyuiPagination('pp'); //定制化分页
        page.bind();
        imPage.init();
    },
    //绑定事件
    bind: function () {
        //批次列表加载
        $("#gdContainerInfo").datagrid({
            columns: [[
                 { field: 'CONTAINERNAME', title: '批次', width: 180 },
                 { field: 'PRODUCTNAME', title: '产品', width: 150 },
                 { field: 'WIPQTY', title: '在制品数量', width: 120 },
                 { field: 'CONTAINERTYPENAME', title: '批次类型', width: 120 },
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 150 },
                 { field: 'STEPINFONAME', title: '工步', width: 120 }
                ]],
            onSelect: function (rowIndex, rowData) {
                page.fillCheckPointData(rowData);
            }
        });
        //检测项列表
        $("#gdCheckPoint").datagrid({
            sortOrder: 'asc',
            remoteSort: false,
            onLoadSuccess: function (data) {
                $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                    total: page.pageTotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
                customizedEasyuiPagination('pp'); //定制化分页
            },
            columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'NAME', title: '关重符号', width: 80, sortable: true },
                 { field: 'CHECKPOINTNOTEDIS', title: '检验内容描述', width: 150, formatter: function (value, row, index) {
                     if (value === null || value === "null") {
                         return "";
                     }
                     return "<span contentEditable='true'>" + value + "</span>";
                 }
                 },
                 { field: 'DRAWINGREQUIREDIS', title: '图纸规定', width: 150, sortable: true
                 },
                 { field: 'INPUTCOUNT', title: '录入次数', width: 80 },
                 { field: 'KEYCHECKNAME', title: '关键过程', width: 80, sortable: true },
                 { field: 'CHECKTYPENAME', title: '关键过程类型', width: 80 },
                 { field: 'MEOPCHECKNAME', title: '工序检', width: 60, sortable: true },
                 { field: 'QUALITYCHECKNAME', title: '质保单', width: 80, sortable: true },
                 { field: 'BUBBLENUMBER', title: '气泡号', width: 80, sortable: true }
                ]],
            onClickRow: function (rowIndex, rowData) {
                $("#gdCheckPoint").datagrid("uncheckAll");
                $("#gdCheckPoint").datagrid("checkRow", rowIndex);
                page.fillCheckPointResultData();
            }
        });
        //结果列表
        $("#gdCheckPointResult").datagrid({
            columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'CHILDCONTAINERNAME', title: '子批次', width: 150 },
                 { field: 'WORKCHECKPOINTRESULTNOTEDIS', title: '工人实测值', width: 200 },
                 { field: 'CREATEDATE', title: '录入时间', width: 100, formatter: function (value, row, index) {
                     if (!isNullOrWhiteSpaceStr(value)) {
                         return dayjs(value).format('YYYY-MM-DD');
                     }
                 }
                 },
                 { field: 'WORKER', title: '工人/三坐标', width: 120 },
                 { field: 'CHECKPOINTRESULTNOTEDIS', title: '检验实测值', width: 200 },
                 { field: 'CHECKDATE', title: '录入时间', width: 100, formatter: function (value, row, index) {
                     if (!isNullOrWhiteSpaceStr(value)) {
                         return dayjs(value).format('YYYY-MM-DD');
                     }
                 }
                 }
                ]],
            onClickRow: function (rowIndex, rowData) {
                $("#gdCheckPointResult").datagrid("uncheckAll");
                $("#gdCheckPointResult").datagrid("checkRow", rowIndex);
                page.fillDocFile(rowData);
            }
        });
        //子序号列表加载
        $("#gdChildContainer").datagrid({
            columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'CONTAINERNAME', title: '子序号批次', width: 180 }
                ]]
        });
        //分页事件
        $('#pp').pagination({
            onSelectPage: function (pageNumber, pageSize) {
                customizedEasyuiPagination('pp'); //定制化分页
                page.pageSize = pageSize; page.pageNumber = pageNumber;
                page.fillCheckPointData();
            }
        });
        //绑定分页go按钮
        $('#pageGo').on("click", function () {
            var pageNumber = $(this).parents('tr').find('.pagination-num').val();
            page.pageNumber = pageNumber;
            page.fillCheckPointData();
        });
        //子序号结果查询
        $("#btnChildSearch").on("click", function () {
            page.fillCheckPointResultData();
        });
        //只看未录入
        $("#isUnInput").on("click", function () {
            page.fillUnInputChildContainer();
        });
        //新增值
        $("#btnAdd").on("click", function () {
            page.addCheckPoint();
        });
        //修改值
        $("#btnEdit").on("click", function () {
            page.editCheckPoint();
        });
        //删除值
        $("#btnDele").on("click", function () {
            page.deleCheckPoint();
        });
        //导出
        $("#btnExport").on("click", function () {
            page.exportCheckPoint();
        });
        //推送三坐标
        $("#btnSendThreeCoordinate").on("click", function () {
            page.sendThreeCoordinate();
        });
    },
    //初始化页面数据
    initPageData: function () {
        var containerDatas = getParam("containerData");
        var uname = getParam("uname"); //员工号
        if (containerDatas === null || uname === null) {
            return;
        }
        containerDatas = Decrypt(containerDatas);
        page.uname = Decrypt(uname);
        var listDatas = JSON.parse(containerDatas);
        var params = {
            action: "InitCheckPointPageByReport",
            containerDatas: JSON.stringify(listDatas.containeridList),
            workflowstepID: listDatas.workflowstepid,
            uname: page.uname
        };
        page.post(page.url, params, true, function (res) {
            if (!res.Result) {
                displayMessage(res.Message, res.Result);
                return;
            }
            var mainData = res.DBDataSet.dtReportContainer;
            if (mainData[0].CONTAINERTYPE === 3) {
                $("#gdChildContainer").datagrid('loadData', { rows: res.DBDataSet.dtChildContainer });
                $("#gdChildContainer").datagrid("checkAll"); //默认全选
            }
            $("#gdContainerInfo").datagrid('loadData', { rows: mainData });
            if (mainData.length === 1) {
                $("#gdContainerInfo").datagrid("selectRow", 0);
            }
        });
    },
    //填充检测项
    fillCheckPointData: function () {
        clearEasyuiDataGrid("gdCheckPoint"); //清空列表
        page.clearFillPage();
        var mainObj = $("#gdContainerInfo").datagrid("getSelected");
        if (mainObj === null) {
            displayMessage("请选择批次", false);
            return;
        }
        var formData = {
            action: "GetStepCheckPointData",
            productID: mainObj.PRODUCTID,
            containerID: mainObj.CONTAINERID,
            workFlowStepId: mainObj.WORKFLOWSTEPID,
            stepInfoID: mainObj.STEPINFOID,
            containerStepWorkReportID: "",
            uname: page.uname,
            pageSize: page.pageSize,
            pageIndex: page.pageNumber
        };
        page.post(page.url, formData, true, function (res) {
            if (!res.Result) {
                displayMessage(res.Message, res.Result);
                return;
            }
            page.pageTotal = res.RowCount;
            $("#gdCheckPoint").datagrid('loadData', { total: res.RowCount, rows: res.DBTable });
        });
    },
    //填充检测项结果（选中的检测项）
    fillCheckPointResultData: function () {
        page.clearFillPage();
        var resData = page.isVaildData();
        if (!resData.result) {
            displayMessage(resData.msg, false);
            return;
        }
        var childObj = $("#gdChildContainer").datagrid("getChecked");
        var childContainer = childObj.map(function (item) {
            return {
                containerid: item.CONTAINERID
            }
        });
        var formdata = {
            action: "GetStepCheckPointResult",
            containerStepWorkReportID: "",
            stepCheckPointId: resData.checkObj.STEPCHECKPOINTID,
            containerId: resData.mainObj.CONTAINERID,
            childContainer: JSON.stringify(childContainer),
            uname: page.uname
        };
        page.post(page.url, formdata, true, function (res) {
            if (!res.Result) {
                displayMessage(res.Message, res.Result);
                return;
            }
            $("#gdCheckPointResult").datagrid('loadData', { rows: res.DBTable });
        });
    },
    //填充未录入子序号
    fillUnInputChildContainer: function () {
        page.disablePageBtn();
        var mainObj = $("#gdContainerInfo").datagrid("getSelected");
        if (mainObj === null) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage("请选择批次", false);
            return;
        }
        var checkObj = $("#gdCheckPoint").datagrid("getSelected");
        if (checkObj === null) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage("请选择检测项", false);
            return;
        }
        var checked = $("#isUnInput").prop('checked');
        if (mainObj.CONTAINERTYPE === "3") {
            var formdata = {
                action: "GetUnInputChildContainer",
                stepCheckPointId: checkObj.STEPCHECKPOINTID,
                containerId: mainObj.CONTAINERID,
                isUnInput: checked,
                uname: page.uname
            };
            page.post(page.url, formdata, true, function (res) {
                page.enablePageBtn(); //恢复所有按钮
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                $("#gdChildContainer").datagrid('loadData', { rows: res.DBTable });
                $("#gdChildContainer").datagrid("checkAll"); //默认全选
                page.clearFillPage();
            });
        }
    },
    //填充显示附件
    fillDocFile: function (row) {
        if (row.WORKRESULTDOCNAME !== null) {
            $("#workdocFile").text(row.WORKRESULTDOCNAME);
            $("#workdocFile").attr("href", row.WORKRESULTDOCPATH);
            $("#workdocFile").attr("download", row.WORKRESULTDOCNAME);
        }
        //        $("#workdocFile").on("click", function () {
        //            $.messager.progress({ text: '', msg: '处理中...' });
        //            var xhr = new XMLHttpRequest();
        ////            if (window.ActiveXObject) {
        ////                // IE6, IE5 浏览器执行代码
        ////                xhr = new ActiveXObject("Microsoft.XMLHTTP");
        ////            } else if (window.XMLHttpRequest) {
        ////                // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        ////                xhr = new XMLHttpRequest();
        ////            }
        //            //设置响应类型为blob类型
        //            xhr.responseType = "blob";
        //            xhr.open("post", page.url, true);
        //            //xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        //            xhr.send("action=GetResultDocFile&resultDocPath=" + row.WORKRESULTDOCPATH);
        //            xhr.onreadystatechange = function () {
        //                $.messager.progress('close');
        //                if (xhr.readyState == 4) {
        //                    if (xhr.status == 200) {
        //                        download(xhr.response, row.WORKRESULTDOCNAME, "txt");
        //                        //                        var csvData = new Blob([this.response]);
        //                        //                        var a = window.document.createElement('a');
        //                        //                        a.href = window.URL.createObjectURL(this.response);
        //                        //                        a.download = xhr.getResponseHeader("filename");
        //                        //                        document.body.appendChild(a)
        //                        //                        a.click();
        //                        //                        document.body.removeChild(a)
        //                    }
        //                }
        //            };
        //        })
    },
    //新增值
    addCheckPoint: function () {
        page.disablePageBtn(); //禁用所有按钮
        var mainObj = $("#gdContainerInfo").datagrid("getSelected");
        if (mainObj === null) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage("请选择批次", false);
            return;
        }
        var childObj = $("#gdChildContainer").datagrid("getChecked");
        if (resData.mainObj.CONTAINERTYPE === "3" && childObj.length === 0) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage("请选择子序号", false);
            return;
        }
        var checkObj = $("#gdCheckPoint").datagrid("getChecked"); //新增可以批量添加检测值
        if (checkObj === null) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage("请选择检测项", false);
            return;
        }
        //获取填写的检测值
        var strCode = $("#pointContent").contents().find("#wucToleranceInput1_ftbFinalHtml_designEditor").contents().find("body").html();
        //        if (isNullOrWhiteSpaceStr(strCode)) {
        //            strCode = $("#pointContent").contents().find("#wucToleranceInput1_uwtMenu__ctl3_ftbHtmlTemp_designEditor").contents().find("body").html();
        //        }
        if (isNullOrWhiteSpaceStr(strCode)) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage("请填写检测值", false);
            return;
        }
        var childContainer = childObj.map(function (item) {
            return {
                containerid: item.CONTAINERID
            }
        });
        var checkPointData = checkObj.map(function (item) {
            return {
                stepCheckPointId: item.STEPCHECKPOINTID
            }
        });
        var formdata = {
            action: "SaveCheckResultByWorker",
            type: "add",
            containerType: mainObj.CONTAINERTYPE,
            stepCheckPointData: JSON.stringify(checkPointData),
            containerId: mainObj.CONTAINERID,
            childContainer: JSON.stringify(childContainer),
            strCode: strCode,
            uname: page.uname
        };
        page.post(page.url, formdata, true, function (res) {
            page.enablePageBtn(); //恢复所有按钮
            if (!res.Result) {
                displayMessage(res.Message, res.Result);
                return;
            }
            page.fillCheckPointData();
        });
    },
    //修改值
    editCheckPoint: function () {
        page.disablePageBtn(); //禁用所有按钮
        var resData = page.isVaildData();
        if (!resData.result) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage(resData.msg, false);
            return;
        }
        //获取填写的检测值
        var strCode = $("#pointContent").contents().find("#wucToleranceInput1_ftbFinalHtml_designEditor").contents().find("body").html();
        //        if (isNullOrWhiteSpaceStr(strCode)) {
        //            strCode = $("#pointContent").contents().find("#wucToleranceInput1_uwtMenu__ctl3_ftbHtmlTemp_designEditor").contents().find("body").html();
        //        }
        if (isNullOrWhiteSpaceStr(strCode)) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage("请填写检测值", false);
            return;
        }
        //获取勾选的结果表
        var checkResultObj = $("#gdCheckPointResult").datagrid("getChecked");
        if (checkResultObj.length === 0) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage("请选择实测值", false);
            return;
        }
        var checkPointResult = checkResultObj.map(function (item) {
            return {
                stepCheckPointResultID: item.STEPCHECKPOINTRESULTID
            }
        });
        var formdata = {
            action: "SaveCheckResultByWorker",
            type: "edit",
            stepCheckPointId: resData.checkObj.STEPCHECKPOINTID,
            containerId: resData.mainObj.CONTAINERID,
            checkPointResult: JSON.stringify(checkPointResult),
            strCode: strCode,
            uname: page.uname
        };
        page.post(page.url, formdata, true, function (res) {
            page.enablePageBtn(); //恢复所有按钮
            if (!res.Result) {
                displayMessage(res.Message, res.Result);
                return;
            }
            page.fillCheckPointResultData();
        });
    },
    //删除实测值结果
    deleCheckPoint: function () {
        page.disablePageBtn(); //禁用所有按钮
        var resData = page.isVaildData();
        if (!resData.result) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage(resData.msg, false);
            return;
        }
        //获取勾选的结果表
        var checkResultObj = $("#gdCheckPointResult").datagrid("getChecked");
        if (checkResultObj.length === 0) {
            page.enablePageBtn(); //恢复所有按钮
            displayMessage("请选择实测值", false);
            return;
        }
        var checkPointResult = checkResultObj.map(function (item) {
            return {
                stepCheckPointResultID: item.STEPCHECKPOINTRESULTID
            }
        });
        //重新赋值
        var formdata = {
            action: "DeleteCheckPointResult",
            deleType: "2",
            checkPointResult: JSON.stringify(checkPointResult),
            uname: page.uname
        };
        page.post(page.url, formdata, true, function (res) {
            page.enablePageBtn(); //恢复所有按钮
            if (!res.Result) {
                displayMessage(res.Message, res.Result);
                return;
            }
            page.fillCheckPointData();
        });
    },
    //导出检测值
    exportCheckPoint: function () {
        page.disablePageBtn();
        var mainObj = $("#gdContainerInfo").datagrid("getSelected");
        if (mainObj === null) {
            page.enablePageBtn();
            resData.msg = "请选择批次";
            return resData;
        }
        var childObj = $("#gdChildContainer").datagrid("getChecked");
        if (mainObj.CONTAINERTYPE === "3" && mainObj.STEPINFOID === "3" && childObj.length === 0) {
            page.enablePageBtn();
            resData.msg = "请选择子序号";
            return resData;
        }
        //主批次
        var container = [mainObj].map(function (item) {
            return {
                containerid: item.CONTAINERID,
                containername: item.CONTAINERNAME,
                StepInfoName: item.STEPINFONAME,
                StepInfoID: item.STEPINFOID,
                Workflowstepname: item.WORKFLOWSTEPNAME,
                workflowstepid: item.WORKFLOWSTEPID
            }
        });
        var childContainer = childObj.map(function (item) {
            return {
                containerid: item.CONTAINERID,
                containername: item.CONTAINERNAME
            }
        });
        var formdata = { action: "ExportCheckPointFileByWorker",
            container: JSON.stringify(container),
            childContainer: JSON.stringify(childContainer),
            uname: page.uname
        };
        page.post(page.url, formdata, true, function (res) {
            page.enablePageBtn(); //恢复所有按钮
            if (!res.Result) {
                displayMessage(res.Message, res.Result);
                return;
            }
            //通过创建a标签实现
            var link = document.createElement("a");
            link.href = res.ReturnData.url;
            //对下载的文件命名
            link.download = res.ReturnData.filename;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        });
    },
    //保存推送三坐标
    sendThreeCoordinate: function () {
        $.messager.confirm('确认', '是否推送给三坐标检测？', function (r) {
            if (r) {
                page.disablePageBtn();
                var mainObj = $("#gdContainerInfo").datagrid("getSelected");
                if (mainObj === null) {
                    page.enablePageBtn(); //恢复所有按钮
                    displayMessage("请选择批次", false);
                    return;
                }
                //获取勾选的结果表
                var checkObj = $("#gdCheckPoint").datagrid("getChecked");
                if (checkObj.length === 0) {
                    page.enablePageBtn(); //恢复所有按钮
                    displayMessage("请选择检测项", false);
                    return;
                }
                var checkPoint = checkObj.map(function (item) {
                    return {
                        stepCheckPointID: item.STEPCHECKPOINTID
                    }
                });
                var formData = {
                    action: "SaveSendThreeCoordinateRecord",
                    mainParam: JSON.stringify(mainObj),
                    checkPoint: JSON.stringify(checkPoint),
                    uname: page.uname,
                    optype: 1//报工
                }
                page.post(page.url, formData, true, function (res) {
                    page.enablePageBtn(); //恢复所有按钮
                    displayMessage(res.Message, res.Result);
                });
            }
        });
    },
    //验证是否有效的数据（通用验证）
    isVaildData: function () {
        var resData = { result: false, msg: "" };
        var mainObj = $("#gdContainerInfo").datagrid("getSelected");
        if (mainObj === null) {
            resData.msg = "请选择批次";
            return resData;
        }
        var checkObj = $("#gdCheckPoint").datagrid("getSelected");
        if (checkObj === null) {
            resData.msg = "请选择检测项";
            return resData;
        }
        resData.result = true;
        resData.mainObj = mainObj;
        resData.checkObj = checkObj;
        return resData;
    },
    //禁用页面按钮
    disablePageBtn: function () {
        //禁用主页面所有按钮
        $("body").find(".easyui-linkbutton").each(function () {
            $(this).linkbutton('disable');
        });
    },
    //恢复页面按钮
    enablePageBtn: function () {
        //恢复主页面所有按钮
        $("body").find(".easyui-linkbutton").each(function () {
            $(this).linkbutton('enable');
        });
    },
    //清除填写结果
    clearFillPage: function () {
        clearEasyuiDataGrid("gdCheckPointResult"); //清空列表
        $("#workdocFile").text("");
        $("#pointContent").contents().find("#wucToleranceInput1_ftbFinalHtml_designEditor").contents().find("body").html("");
        //        $("#pointContent").contents().find("#wucToleranceInput1_uwtMenu__ctl3_ftbHtmlTemp_designEditor").contents().find("body").html("");
    },
    //post数据（路径，参数，是否异步，成功返回方法）
    post: function (url, param, async, callback) {
        $.ajax({
            type: "Post",
            url: url,
            data: param,
            cashe: false,
            async: async,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
                page.enablePageBtn();
            }
        });
    }
};

//文件上传或导入对象
var imPage = {
    init: function () {
        imPage.checkPointUpLoader();
        imPage.docFileUpLoader();
    },
    //检测项导入组件初始化
    checkPointUpLoader: function () {
        var uploader = WebUploader.create({
            // swf文件路径
            swf: page.rootPath + "/Content/webuploader/Uploader.swf",
            // 文件接收服务端。
            server: page.url,
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#btnImportCp',
            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            formData: {
                action: "ImportCheckPointFileByWorker",
                uname: page.uname
            },
            accept: {
                title: 'Excel',
                extensions: 'xlsx,xls',
                mimeTypes: 'excel/*'
            }
        });
        // 当有文件被添加进队列的时候，每次只传一个文件
        uploader.on('fileQueued', function (file) {
            clearMessage();
            page.disablePageBtn();
            uploader.upload();
            $.messager.progress({ text: '', msg: '处理中...' });
        });
        //上传成功
        uploader.on('uploadSuccess', function (file, response) {
            clearMessage();
            var result = response;
            $.messager.progress('close');
            displayMessage(result.Message, result.Result);
            var f = uploader.getFile(file.id); //找到上传的文件
            uploader.removeFile(f, true); //将其从队列中的删掉
            page.enablePageBtn(); //恢复所有按钮
        });
        //上传失败
        uploader.on('uploadError', function (file) {
            displayMessage("上传失败", false);
            var f = uploader.getFile(file.id); //找到上传的文件
            uploader.removeFile(f, true); //将其从队列中的删掉
            $.messager.progress('close');
            page.enablePageBtn(); //恢复所有按钮
        });
    },
    //附件上传组件初始化
    docFileUpLoader: function () {
        var docUploader = WebUploader.create({
            // swf文件路径
            swf: page.rootPath + "/Content/webuploader/Uploader.swf",
            // 文件接收服务端。
            server: page.url,
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#btnSeleDocFile',
            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            multiple: false
        });
        // 当有文件被添加进队列的时候，每次只传一个文件
        docUploader.on('fileQueued', function (file) {
            if ($('#txtDocFileId').val() != "") {
                var f = docUploader.getFile($('#txtDocFileId').val()); //找到上一次队列中的文件
                docUploader.removeFile(f, true); //删除掉上一次队列中的文件
            }
            $('#txtDocFileName').textbox('setValue', file.name);
            $('#txtDocFileId').val(file.id);
        });
        //上传成功
        docUploader.on('uploadSuccess', function (file, response) {
            clearMessage();
            var result = response;
            $.messager.progress('close');
            displayMessage(result.Message, result.Result);
            var f = docUploader.getFile(file.id); //找到上传的文件
            docUploader.removeFile(f, true); //将其从队列中的删掉
            page.enablePageBtn(); //恢复所有按钮
        });
        //上传失败
        docUploader.on('uploadError', function (file) {
            displayMessage("上传失败", false);
            var f = docUploader.getFile(file.id); //找到上传的文件
            docUploader.removeFile(f, true); //将其从队列中的删掉
            $.messager.progress('close');
            page.enablePageBtn(); //恢复所有按钮
        });

        //上传
        $("#btnUploadDocFile").on("click", function () {
            page.disablePageBtn();
            //获取勾选的结果表
            var checkResultObj = $("#gdCheckPointResult").datagrid("getChecked");
            if (checkResultObj.length === 0) {
                page.enablePageBtn(); //恢复所有按钮
                displayMessage("请选择实测值", false);
                return;
            }
            if ($('#txtDocFileId').val() === "") {
                page.enablePageBtn(); //恢复所有按钮
                displayMessage("请选择附件", false);
                return;
            }
            var checkPointResult = checkResultObj.map(function (item) {
                return {
                    stepCheckPointResultID: item.STEPCHECKPOINTRESULTID,
                    docType: $("#selDocType").combobox('getValue')
                }
            });
            //设置上传参数
            docUploader.options.formData = {
                action: "SaveCheckPointResultDocFile",
                uname: page.uname,
                uploadType: 1,
                checkPointResult: JSON.stringify(checkPointResult)
            };
            docUploader.upload();
            $.messager.progress({ text: '', msg: '处理中...' });
        });
    }
};

$(function () {
    page.init();
    $('.webuploader-pick').css("padding", "2px 4px"); //改变上传按钮样式
});

//二维码业务
var qrCode = {
    url: getRootPath() + "/Ashx/InputCheckItemQrCodeFormHandler.ashx", //后台处理url,
    type: getParam('type'),
    getContainerQRCode: function () {
        var rows = $('#gdContainerInfo').datagrid('getRows');
        var Crows = $('#gdChildContainer').datagrid('getRows');
        var childRows = $("#gdChildContainer").datagrid("getChecked");
        var cpRows = $("#gdCheckPoint").datagrid("getChecked");
        var containers = [];
        var childContainer = [];
        var checkPoint = [];
        if (cpRows.length == 0) { displayMessage("请选择检测项", false); return; }
        if (Crows.length > 0 && childRows.length == 0) { displayMessage("请选择子批次信息", false); return; }

        $.each(rows, function (index, item) {
            containers.push(item.CONTAINERNAME);
        });
        $.each(cpRows, function (index, item) {
            checkPoint.push(item.STEPCHECKPOINTID);
        });
        $.each(childRows, function (index, item) {
            childContainer.push(item.CONTAINERID);
        });

        var formdata = { action: "getContainerQRCode", containernames: containers.join(','), childContainers: childContainer.join(','), checkPoints: checkPoint.join(',') };
        page.post(qrCode.url, formdata, true, function (res) {
            //alert(res.ReturnData);
            $('#qrCodeHtml').html(res.ReturnData)
            $('#Total').val(res.PageCount)
            $('#CurrentIndex').val(1)
            $('#showCurrent').html("1/" + res.PageCount)
        })
    },
    showPre: function () {
        var index = Number($('#CurrentIndex').val())
        if (index > 1) {
            $('.Imgdiv_' + index).prev().removeClass('hiddenImg')
            $('.Imgdiv_' + index).addClass('hiddenImg');
            $('#CurrentIndex').val(index - 1)
            $('#showCurrent').html((index - 1) + "/" + $('#Total').val())
        }
    },
    showNext: function () {
        var index = Number($('#CurrentIndex').val());
        var total = Number($("#Total").val());
        if (index < total) {
            $('.Imgdiv_' + index).next().removeClass('hiddenImg')
            $('.Imgdiv_' + index).addClass('hiddenImg');
            $('#CurrentIndex').val(index + 1)
            $('#showCurrent').html((index + 1) + "/" + $('#Total').val())
        }
    },
    textBoxOnblur: function (val) {
        if (val == "") { return; }
        page.post(qrCode.url, { action: 'importQRCode', val: val }, true, function (res) {
            $('#importText').val('').focus();
            $('#importCount').html(res.PageCount);
            if (res.Message != "") {
                displayMessage(res.Message, false);
            }
        });
    },
    submitForm: function () {
        var importCount = $('#importCount').html();
        if (importCount == "0") {
            displayMessage("请先扫码再进行操作", false); return;
        }
        var mainObj = $("#gdContainerInfo").datagrid("getSelected");
        $.messager.confirm('温馨提示', "确认提交已扫码数据吗？", function (r) {
            page.post(qrCode.url, { action: 'saveQRCode', type: qrCode.type, containerStepWorkReportID: qrCode.type == "2" ? "" : "" }, true, function (res) {
                $('#importCount').html('0');
                displayMessage(res.Message, res.Result);
            })
        });
    }
};